package com.liao.ticket.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private static String formDay = "yyyy-MM-dd";

    private static String formMinutes = "yyyy-MM-dd HH:mm";

    public static String toStringDay(Timestamp timestamp, Integer num) {
        SimpleDateFormat format = new SimpleDateFormat(formDay);
        String date = format.format(timestamp.getTime() + (num * 24 * 60 * 60 * 1000));
        return date;
    }

    public static String toStringMinutes(Timestamp timestamp,Integer num){
        SimpleDateFormat format = new SimpleDateFormat(formMinutes);
        String date = format.format(timestamp.getTime() + (num * 60 * 1000));
        return date;
    }

    public static Long toLongDay(String date, Integer num) {
        SimpleDateFormat format = new SimpleDateFormat(formDay);
        try {
            Long time = format.parse(date).getTime() + (num * 24 * 60 * 60 * 1000);
            return time;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Long toLongMinutes(String date, Integer num) {
        SimpleDateFormat format = new SimpleDateFormat(formMinutes);
        try {
            Long time = format.parse(date).getTime() + (num * 60 * 1000);
            return time;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Timestamp(1662220800000L));
    }

}
